﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace ExamServer.Forms
{
    public partial class DialogBackUp : Form
    {
        public DialogBackUp()
        {
            InitializeComponent();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (textBox1.Text == "")
            {
                MessageBox.Show("请填写备份路径！");
                return;
            }
            DBConnection db = new DBConnection();
            string fileName = null;
            switch (comboBox1.SelectedIndex)
            {
                case 0:
                    fileName = db.BackUp("Pro_Database_Full_Backup", textBox1.Text);
                    Properties.Settings.Default.DefaultPath_BackUp_Full = textBox1.Text;
                    break;
                case 1:
                    fileName = db.BackUp("Pro_Database_Diff_Backup", textBox1.Text);
                    Properties.Settings.Default.DefaultPath_BackUp_Diff = textBox1.Text;
                    break;
                case 2:
                    fileName = db.BackUp("Pro_Log_Full_Backup", textBox1.Text);
                    Properties.Settings.Default.DefaultPath_BackUp_Log = textBox1.Text;
                    break;
                default:
                    MessageBox.Show("未知错误!");
                    break;
            }
            Properties.Settings.Default.Save();
            MessageBox.Show("备份成功！备份文件名为：" + fileName);
            this.Close();
        }

        private void DialogBackUp_Load(object sender, EventArgs e)
        {
            textBox1.Text = Properties.Settings.Default.DefaultPath_BackUp_Full;
            comboBox1.SelectedIndex = 0;
        }

        private void comboBox1_DropDownClosed(object sender, EventArgs e)
        {
            switch (comboBox1.SelectedIndex)
            {
                case 0:
                    textBox1.Text = Properties.Settings.Default.DefaultPath_BackUp_Full;
                    break;
                case 1:
                    textBox1.Text = Properties.Settings.Default.DefaultPath_BackUp_Diff;
                    break;
                case 2:
                    textBox1.Text = Properties.Settings.Default.DefaultPath_BackUp_Log;
                    break;
                default:
                    MessageBox.Show("未知错误!");
                    break;
            }
        }
    }
}
